<?php

use backend\widgets\Bar;
use backend\grid\CheckboxColumn;
use backend\grid\ActionColumn;
use backend\grid\GridView;
use yii\widgets\Pjax;
use common\libs\Constants;
use yii\bootstrap\Html;
use backend\models\Mission;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\search\MissionSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title                   = '任务';
$this->params['breadcrumbs'][] = '任务';
?>
<div class="row">
    <div class="col-sm-12">
        <div class="ibox">
            <?= $this->render('/widgets/_ibox-title') ?>
            <div class="ibox-content">
                <?= Bar::widget() ?>
                <!--                --><? //= $this->render('_search', ['model' => $searchModel]); ?>
                <?php Pjax::begin(); ?>            <?= GridView::widget([
                    'dataProvider' => $dataProvider,
                    'filterModel'  => $searchModel,
                    'columns'      => [
                        ['class' => CheckboxColumn::className()],

                        [
                            'attribute' => 'id',
                            'width'     => '5px'
                        ],
                        [
                            'attribute' => 'username',
                            'label'     => '用户',
                            'value'     => function ($model) {
                                /**
                                 * @var \api\models\PartTimeJob $model
                                 */
                                return $model->u->username;
                                //显示认证信息
                            }

                        ],

                        'title',
                        [
                            'attribute' => 'view_num',
                        ],
//                        'content:ntext',
//                        'salary',
                        [
                            'attribute' => 'pay_type',
                            'filter'    => Constants::getPayType(),
                            'value'     => function ($model) {
                                if (isset($model->pay_type)) {
                                    return Constants::getPayTypeMission($model->pay_type);
                                } else {
                                    return $model->pay_type;
                                }
                            }
                        ],
                        [
                            'attribute' => 'status',
                            'filter'    => Constants::getPayStatus(),
                            'format'    => 'raw',
                            'value'     => function ($model) {
//                                return Constants::getYesNoItems($model->status);
                                /**
                                 * @var \backend\models\search\MissionSearch $model
                                 */

//                                return Constants::getForbiddenStatus($model->forbidden);

                                return Html::a(Constants::getPayStatus($model->status),
                                    ['update', 'id' => $model['id']], [
                                        'class'        => 'btn btn-xs btn-rounded ' . ($model->status != Mission::NOT_PAY_STATUS ? 'btn-info' : 'btn-default'),
                                        'data-confirm' => $model->status != Mission::NOT_PAY_STATUS ? '确定设置为未支付?' : '确定设置为支付?',
                                        'data-method'  => 'post',
                                        'data-pjax'    => '0',
                                        'data-params'  => [
                                            $model->formName() . '[status]' => $model->status != Mission::NOT_PAY_STATUS ? Mission::NOT_PAY_STATUS : Mission::PAY_STATUS
                                        ]
                                    ]);
                            }
                        ],
                        [
                            'attribute' => 'forbidden',
                            'filter'    => Constants::getForbiddenStatus(),
                            'value'     => function ($model) {
                                /**
                                 * @var \backend\models\Mission $model
                                 */

//                                return Constants::getForbiddenStatus($model->forbidden);

                                return Html::a(Constants::getForbiddenStatus($model->forbidden),
                                    ['update', 'id' => $model['id']], [
                                        'class'        => 'btn btn-xs btn-rounded ' . ($model->forbidden != Mission::FORBIDDEN ? 'btn-info' : 'btn-default'),
                                        'data-confirm' => $model->forbidden != Mission::FORBIDDEN ? '确定此内容违规?' : '确定此内容正常?',
                                        'data-method'  => 'post',
                                        'data-pjax'    => '0',
                                        'data-params'  => [
                                            $model->formName() . '[forbidden]' => $model->forbidden != Mission::FORBIDDEN ? Mission::FORBIDDEN : Mission::ACCESS
                                        ]
                                    ]);
                            },
                            'format'    => 'raw'
                        ],

                        // 'pay_needed',
                        // 'title',l;p[
                        // 'created_at',
                        // 'updated_at',
                        // 'contact_name',
                        // 'contact_phone',
                        [
                            'class'     => \backend\grid\DateColumn::className(),
                            'attribute' => 'created_at'
                        ],

                        [
                            'class'    => ActionColumn::className([
                            ]),
                            'template' => '{view-layer} {update} {delete} {user-list}',
                        ],
                    ],
                ]); ?>
                <?php Pjax::end(); ?>            </div>
        </div>
    </div>
</div>
